﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using Table_Dal;
using DAL;
using BLL;
using ApplicationLayer.Obj_frmCaNhan;
namespace ApplicationLayer
{
    public partial class frmCaNhan : DevComponents.DotNetBar.OfficeForm
    {
        string user = "";
        public frmCaNhan(string s)
        {
            user = s;
            InitializeComponent();
        }
        public frmCaNhan()
        {
            InitializeComponent();
        }
        public void load(string s)
        {
            NguoiradeBll nrdBll = new NguoiradeBll();
            NguoiradeTbl nrd = new NguoiradeTbl();
            nrd = nrdBll.ThongTin(s);
            txtTen.Text = nrd.TENNGUOIRADE;
            int x = 0;
            if (nrd.HINHANH != null && nrd.HINHANH != "")
            {
                x = 1;
                
            }
            pic_HinhAnh.ImageLocation = nrdBll.PictureLink(x, nrd.MANGUOIRADE);
            if (nrd.GIOITINH == 1)
            {
                cbox_GioiTinh.SelectedIndex = 0;
            }
            else
            {
                cbox_GioiTinh.SelectedIndex = 1;
            }
            lblTenDangNhap.Text = user;
            QuantriBll qt = new QuantriBll();
            string chucvu = "";
            if (qt.PhanQuyen(s) == 0)
                chucvu = "Administator";
            else
                chucvu = "User";
            txtQuyen.Text = chucvu;
            txtDiaChi.Text = nrd.DIACHI;
            txtPass.Text = nrd.MATKHAU;
            if (nrd.NGAYSINH.ToString().Trim().Length>0)
            {
                txtNgaySinh.Text = nrd.NGAYSINH.ToShortDateString();
            }
           
        }
        
        private void frmCaNhan_Load(object sender, EventArgs e)
        {
            load(user);   
        }
        private void txtSodt_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar < '0' || e.KeyChar > '9')
                e.Handled = true;
        }
        private void lblChangePass_Click_1(object sender, EventArgs e)
        {
            
            frmChangePassword frm = new frmChangePassword(user,txtPass.Text);
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                load(user);
                MessageBox.Show("Đổi mật khẩu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

        }
        
    }
}